package com.ruoyi.my.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.WebTakeTime;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.GrRentRecord;
import com.ruoyi.system.service.IGrRentRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租房记录Controller
 *
 * @author liuxusheng
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/system/record")
public class GrRentRecordController extends BaseController {
    @Autowired
    private IGrRentRecordService grRentRecordService;

    /**
     * 查询租房记录列表
     */
    @WebTakeTime
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrRentRecord grRentRecord) {
        startPage();
        List<GrRentRecord> list = grRentRecordService.selectGrRentRecordList(grRentRecord);
        return getDataTable(list);
    }

    /**
     * 导出租房记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "租房记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrRentRecord grRentRecord) {
        List<GrRentRecord> list = grRentRecordService.selectGrRentRecordList(grRentRecord);
        ExcelUtil<GrRentRecord> util = new ExcelUtil<GrRentRecord>(GrRentRecord.class);
        util.exportExcel(response, list, "租房记录数据");
    }

    /**
     * 获取租房记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(grRentRecordService.selectGrRentRecordById(id));
    }

    /**
     * 新增租房记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "租房记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrRentRecord grRentRecord) {
        return toAjax(grRentRecordService.insertGrRentRecord(grRentRecord));
    }

    /**
     * 修改租房记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "租房记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrRentRecord grRentRecord) {
        return toAjax(grRentRecordService.updateGrRentRecord(grRentRecord));
    }

    /**
     * 删除租房记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "租房记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(grRentRecordService.deleteGrRentRecordByIds(ids));
    }
}
